package com.wgy.blog.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.wgy.blog.mapper.UserMapper;
import com.wgy.blog.pojo.Login;
import com.wgy.blog.pojo.PageQuery;
import com.wgy.blog.pojo.User;
import com.wgy.blog.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.RequestBody;

import javax.annotation.Resource;
import java.util.List;

/**
 * @Author:Iny
 * @Data：2021/11/6 12:06
 */
@Service
public class UserServiceImpl implements UserService {

    @Resource
    private UserMapper userMapper;
    @Override
    public PageInfo<User> findAll( PageQuery pageQuery) {
        PageHelper.startPage(pageQuery.getPageNum(),pageQuery.getPageSize());
        List<User> all = userMapper.findAll();
        return new PageInfo<>(all);
    }

    @Override
    public User getUserByName(String userName) {
        User user = userMapper.getUserByName(userName);
        return user;
    }

    @Override
    public String login(Login login) {
        User user = userMapper.getUserByName(login.getUsername());
         if (login.getPassword().equals(user.getPassword())){
             return login.getUsername();
         }
        return null;
    }

    @Override
    public User findById(int id) {
        return userMapper.findById(id);
    }

    @Override
    public int update(User user) {
        int update = userMapper.update(user);
        return update;
    }
}
